
require(foreign)

require(stats4)
require(mfx)
require(stargazer)

#import data
symmetrydata=read.dta("CompressionExpt1.dta")
symmetryframe=data.frame(id=symmetrydata$var1,user_id=symmetrydata$var2,qn=symmetrydata$var3,qid=symmetrydata$var4,order=symmetrydata$var5,bid=symmetrydata$var6,chosen_act=symmetrydata$var9, true_state=symmetrydata$var10)

#reward value
r=10 

#data frame for letters
symframeletters=subset(symmetryframe,user_id<1700)
symframeletters$correct=(symframeletters$true_state<=13 & symframeletters$chosen_act==1)+(symframeletters$true_state>13 & symframeletters$chosen_act==2)
unique(symframeletters$qid)

#data frame for balls
symframeballs=subset(symmetryframe,user_id>1700)
symframeballs$true_state=symframeballs$true_state+6*(symframeballs$qid==3)+4*(symframeballs$qid==4)+2*(symframeballs$qid==5)
symframeballs$correct=(symframeballs$true_state<=10 & symframeballs$chosen_act==1)+(symframeballs$true_state>10 & symframeballs$chosen_act==2)
ballsqid=unique(symframeballs$qid)

#Variables to be stored
acculin=matrix(rep(0,80),nrow=4,ncol=20)
accupow=matrix(rep(0,80),nrow=4,ncol=20)
accugen=matrix(rep(0,80),nrow=4,ncol=20)
accuexp=matrix(rep(0,80),nrow=4,ncol=20)
accunoneigh=matrix(rep(0,80),nrow=4,ncol=20)
dataaccu=matrix(rep(0,80),nrow=4,ncol=20)

#number of states used by different treatments
Nvec=c(8,12,16,20)

#States for different treatments
states=list()
states[[1]]=c(7:14)
states[[2]]=c(5:16)
states[[3]]=c(3:18)
states[[4]]=c(1:20)

correct=list()
incorrect=list()

symframeballs$distance=abs(symframeballs$true_state-10.5)


